package indi.kider.server.applet.service;

import indi.kider.common.model.apabus.Notice;
import indi.kider.server.apabus.mapper.NoticeMapper;
import indi.kider.server.applet.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@SuppressWarnings("ALL")
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public List<Notice> getNoticeInfo(User user) {
        Notice notice = new Notice();
        notice.setRecipientId(user.getId());
        notice.setSeeState(1);
        List<Notice> noticeList = noticeMapper.select(notice);
        return noticeList;
    }

    @Override
    public String updateNotice(Notice notice) {
        if(notice.getNoticeId() != null){
            String ids[] =  notice.getNoticeId().split(",");
            for(String s : ids){
                notice.setId(Long.valueOf(s));
                notice.setSeeState(2);
                noticeMapper.updateByPrimaryKeySelective(notice);
            }
        }else{
            notice.setSeeState(2);
            noticeMapper.updateByPrimaryKeySelective(notice);
        }
        return "";
    }


}
